<?php
// 首页显示信息以及基本配置
namespace Partner\Controller;
use Think\Controller;
class UserController extends CommonController{
    function _initialize(){
        if(session('user_id') ){
           $this->redirect('/');
        }
    }

   function login(){
        if($_POST){
            $password=I('post.pword');
            $phone=I('post.uname');
            if( !$phone|| !$password ){
                $this->ajax_r(0,'','请输入手机号和密码！');
            }
            $users=M('users');
            $userArrayFlag	=	$users->where(' phone = "'.$phone.'" AND ishidden = 1')->find();
            if( !$userArrayFlag ){
                $this->ajax_r(0,'','未查询到该用户信息！');
            }
            $pass=passport_decrypt($userArrayFlag['password'],'wnsc');

            if($pass==$password){
                $rs=M('partner')->where('u_id='.$userArrayFlag['id'])->find();

                if($rs['status']==1){
                    session('id',$rs['id']);
                    session('u_id',$rs['u_id']);
                    session('user_id',$userArrayFlag['id']);
                    session('name',$userArrayFlag['username']);
                    session('level',$rs['level']);
                    session('b_id',$rs['b_id']);
                    $url    =   $_POST['loginurl']?$_POST['loginurl']:'/Index/index';
                    $this->ajax_r(1,$url,'登录成功！');
                }else{
                    $this->ajax_r(0,'','该账户被禁用！');
                }

            }else{
                $this->ajax_r(0,'','密码错误！');
            }
        }else{
            $this->display();
        }
    }

    public function ajax_r($code='0',$data='',$message='') {
        $msg['code']=$code;
        $msg['data']=$data;
        $msg['message']=$message;
        $this->ajaxReturn($msg);
    }



}